import { IEngine } from "./engine/IEngine";
import { LayerItem } from "./ui/ui";
import { IModel } from "./mvc/view/IModel";
import { UIView } from "./mvc/view/UIView";
import { IController } from "./mvc/view/IController";

export type EventHandler = (data: any) => void

export interface IValid {
    isValid?(): boolean;
}

export interface IAppEvent {
    topic: string;
    data?: any;
    handler?: EventHandler
    target?: IValid;
    isBlock?: boolean;
}

export interface IEventDispatcher {
    on(event: IAppEvent): void
    on(topic: string, handler: EventHandler, target: IValid): void
    off(event: IAppEvent): void
    off(topic: string, handler: EventHandler, target: IValid): void
    emit(type: string, data: any): void
}

export interface IMediator {
    // publish(e: IAppEvent): void
    publish(topic: string, data: any): void
    // publish(param: any, data?: any): void
    subscribe(e: IAppEvent): void;

    unsubscribe(e: IAppEvent): void;

}



export interface IControllerDetails {
    conrollerName: string;
}

export interface IAppSettings {
    isDebug: boolean;
    root: any
    uiSettings: LayerItem[]
    engine: IEngine
    onErrorHandler: (o: Object) => void
}

export interface IRoute {
    controllerName: string;
    actionName: string;
    args: any[]
}

export interface IEventEmitter {
    triggerEvent(topic: string, data: any): void
    subscribeEvents(events: IAppEvent[]): void
    unsubscribeToEvents(): void;

}

export interface IRouter extends IEventEmitter {
    init(): void;
}

export interface IDispatcher extends IEventEmitter {
    init(): void;
}

export interface ILoader extends IEventEmitter {
    init(): void;
}



export type UIParam = {
    path: string,//预制体的路径+预制体名称
    bundle?: string,//隶属于哪个bundle
    model?: IModel,//模型
    controller: IController,
    layerIndex: number,//UIManager中的哪一个层级
    className?: any,//组件名称，不传递默认使用预制体的名称
    parent?: any,//父节点，如果使用父节点就不会添加到UIManager中
    callback?: (view: UIView) => void,//加入节点后的调用
    delayTime?: number,//延迟多久后加入节点中
    id?: any,//功能ID。为了支持填表使用。
    param?: any,//参数
    canMulty?: boolean
}